package cn.kgc.mybatis.web.service.impl;

import cn.kgc.mybatis.web.dto.DeptPageDTO;
import cn.kgc.mybatis.web.entity.Dept;
import cn.kgc.mybatis.web.mapper.DeptMapper;
import cn.kgc.mybatis.web.service.DeptService;
import cn.kgc.mybatis.web.utils.MybatisUtil;
import cn.kgc.mybatis.web.vo.ResponseResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import java.util.List;

/**
 * @author 课工场
 * @date 2024/10/31
 * @description
 */
public class DeptServiceImpl implements DeptService {

    private DeptMapper  deptMapper = MybatisUtil.creatMapperProxy(DeptMapper.class);
    @Override
    public ResponseResult deptPage(DeptPageDTO deptPageDTO) {

        PageHelper.startPage(deptPageDTO.getPage(),deptPageDTO.getLimit());
        // 搜索查询语句
        List<Dept> depts =  deptMapper.searchDept(deptPageDTO.getDeptName(),deptPageDTO.getLocal());

        PageInfo<Dept> deptPageInfo = new PageInfo<>(depts);
        long total = deptPageInfo.getTotal();

        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(0);
        responseResult.setData(depts);
        responseResult.setCount(total);

        return responseResult;
    }
}
